package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import po.Bandwidth;
import po.Result;
import service.BandwidthService;

import java.util.List;

@Controller
@RequestMapping("/bandwidth")
public class BandwidthController {
    @Autowired
    private BandwidthService bandwidthService;

    @RequestMapping("/getBandwidthInfoView")
    public String getBandwidthInfoView() {
        return "resource/bandwidthInfo";
    }

    @RequestMapping("/findAllBandwidths")
    public @ResponseBody
    List<Bandwidth> findAllBandwidths() throws Exception {
        return bandwidthService.findAllBandwidths();
    }

    @RequestMapping("/getAddBandwidthView")
    public String getAddBandwidthView() {
        return "resource/addBandwidth";
    }

    @RequestMapping("/addBandwidth")
    public @ResponseBody
    Result addBandwidth(Bandwidth bandwidth) {
        return bandwidthService.addBandwidth(bandwidth);
    }

    @RequestMapping("/deleteBandwidthById")
    public @ResponseBody
    Result deleteBandwidthById(int id) {
        return bandwidthService.deleteBandwidthById(id);
    }

    @RequestMapping("/getEditBandwidthView")
    public String getEditBandwidthView() {
        return "resource/editBandwidth";
    }

    @RequestMapping("/updateBandwidth")
    public @ResponseBody
    Result updateBandwidth(Bandwidth bandwidth) {
        return bandwidthService.updateBandwidthById(bandwidth.getId(), bandwidth);
    }
}
